package com.chenfan.process.entity.po;

import com.chenfan.process.enums.CarbonCopyEnum;
import org.springframework.beans.BeanUtils;

import com.baomidou.mybatisplus.annotation.TableName;
import com.chenfan.ccp.util.tool.UuidUtil;
import com.chenfan.process.dto.ApprovalCallBack;

import lombok.Data;

import java.util.Objects;

/**
 * @author liuming
 * @date 2021/8/13
 */
@Data
@TableName("process_cc")
public class ProcessCarbonCopyPo {

    public static final String PROCESS_ID = "process_id";
    public static final String APPROVAL_TEMPLATE_ID = "approval_template_id";

    private Long id;

    private Long processId;

    private Long approvalTemplateId;

    private Integer type;

    private Long relatedId;

    private String relatedName;

    private String url;

    private String title;

    private Integer status;

    public static ApprovalCallBack.CarbonCopyDTO toDTO(ProcessCarbonCopyPo processCarbonCopyPo) {
        return ApprovalCallBack.CarbonCopyDTO.builder().userId(processCarbonCopyPo.getRelatedId())
            .userName(processCarbonCopyPo.getRelatedName()).type(processCarbonCopyPo.getType())
            .url(processCarbonCopyPo.getUrl()).nodeName(processCarbonCopyPo.getTitle()).build();
    }

    public ProcessCarbonCopyPo cloneCarbonCopy() {
        ProcessCarbonCopyPo copy = new ProcessCarbonCopyPo();
        BeanUtils.copyProperties(this, copy);
        copy.setId(UuidUtil.generateId());
        return copy;
    }

    public boolean normal() {
        return Objects.equals(getType(), CarbonCopyEnum.NORMAL.getCode());
    }
}
